package me.piebridge.douban;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Files {

	public static String readAsString(File file) throws IOException {
		return readAsString((new FileInputStream(file)));
	}
	
	public static String readAsString(InputStream is) throws IOException {
		int length;
		byte[] bytes = new byte[8192];
		BufferedInputStream bis = new BufferedInputStream(is);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		while ((length = bis.read(bytes)) != -1) {
			baos.write(bytes, 0, length);
		}
		bis.close();
		return baos.toString("UTF-8");
	}

}
